#include <iostream>
#include <fstream>
#include <string>
#include "message.pb.h"
using namespace std;

int main()
{
    demo::msg person1;
    person1.set_name("handsomeboy");
    person1.set_gender("man");
    person1.set_id(1);

    string buffer;
    person1.SerializePartialToString(&buffer);
    cout<<buffer<<endl;

    demo::msg person2;
    person2.set_name("beautifulgirl");
    person2.set_gender("woman01");
    person2.set_id(2);
    
    person2.AppendPartialToString(&buffer);
    cout<<buffer<<endl;

    ofstream ofs("./file", ios::out | ios::binary);
    if (!ofs.is_open())
    {
        return -1;
    }

    ofs.write(buffer.c_str(),buffer.size());

    ofs.close();

    return 0;
}